import 'package:flutter_smart_heating/common/http.dart';
import 'package:get/get.dart';

import 'state.dart';

class SupportDetailLogic extends GetxController {
  final state = SupportDetailState();

  fetchData() async {
    var res = await Http.instance.post(
      '/plugin/help_center/api/detail',
      data: {'id': Get.parameters['id']},
    );
    state.stateController.setStatus(res);
    if (res.code == 1) {
      state.row = res.data;
    }
    update();
  }

  submitReport(type) async {
    var res = await Http.instance.post(
      '/plugin/help_center/api/report',
      data: {
        'id': state.row['id'],
        'type': type,
      },
    );

    if (res.code == 1) {
      state.row['unsolved_count'] = res.data['unsolved_count'];
      state.row['solved_count'] = res.data['solved_count'];
    }
    update(['report']);
  }
}
